//
//  PPCommentTableViewCell.m
//  pet
//
//  Created by 陈无忌 on 11/27/14.
//  Copyright (c) 2014 whalefin. All rights reserved.
//

#import "PPCommentTableViewCell.h"
#import "supportingHeadFiles.h"

@implementation PPCommentTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)configCellWithReply:(PPComment *)reply
{
    [self.commentAvatar setImageWithURL:[PPImageUrl getImageUrl:reply.userAvatar] placeholderImage:[UIImage imageNamed:@"defaultAvatar"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    if (reply.targetUserName.length > 0) {
        self.commentContentLabel.text = [NSString stringWithFormat:@"回复%@：%@",reply.targetUserName,reply.content];
    }else{
        self.commentContentLabel.text = reply.content;
    }
    
    self.commentContentLabel.frame = CGRectMake(58, 9, 245, 12);
    self.commentContentLabel.numberOfLines = 0;
    self.commentContentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    [self.commentContentLabel sizeToFit];
    if (self.commentContentLabel.frame.size.height > 29) {
        self.timeLabel.frame = CGRectMake(205, 9 + self.commentContentLabel.frame.size.height + 4, 95, 9);
    }else{
        self.timeLabel.frame = CGRectMake(205, 40, 95, 9);
    }
    self.timeLabel.text = reply.publicDate;
    CGRect frame = self.commentContentLabel.frame;
    if (frame.size.height <= 15) {
        frame.origin.y = 19;
        self.commentContentLabel.frame = frame;
    }
    
    CGRect cellFrame = CGRectMake(0, 0, 320, [self getCellHeightWithReply:reply]);
    self.BGIMG.frame = cellFrame;
    

}


+ (CGFloat)getCellHeightWithReply:(PPComment *)reply{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(58, 9, 245, 12)];
    label.font = [UIFont systemFontOfSize:12.0];
    label.text = reply.content;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByCharWrapping;
    [label sizeToFit];
    if (label.frame.size.height > 29) {
        return 9 + label.frame.size.height + 4 + 9 + 5;
    }else{
        return 55;
    }
}

- (CGFloat)getCellHeightWithReply:(PPComment *)reply
{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(58, 9, 245, 12)];
    label.font = [UIFont systemFontOfSize:12.0];
    label.text = reply.content;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByCharWrapping;
    [label sizeToFit];
    if (label.frame.size.height > 29) {
        return 9 + label.frame.size.height + 4 + 9 + 5;
    }else{
        return 55;
    }
}

@end
